package com.crocodile.game17.web;

import com.crocodile.game17.common.R;
import com.crocodile.game17.pojo.User;
import com.crocodile.game17.service.LoginService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags ="登录相关接口")
@RestController
@Slf4j
@RequestMapping("/gate")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping(value="/login" )
    public R<Map> login(@RequestBody User user){

        log.info("用户登录：{}", user);

        return loginService.login(user);
    }

    /**
     * 退出登录
     * @return
     */
    @GetMapping("/logout")
    public R<String> logout(){

        SecurityContextHolder.clearContext();
        return R.success("退出成功");
    }

}
